using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using System.Security.Permissions;
using NBusiness.CodeDom.Properties;

namespace NBusiness.CodeDom.Compiler
{
    [Serializable]
	public class EntityCompilationException : Exception
	{
		private EntityElement _element;

		public EntityElement Element
		{
			get { return _element; }
		}

        public EntityCompilationException() { }

		public EntityCompilationException(string message)
			: base(message)
		{ }

		public EntityCompilationException(string message, Exception innerException)
			: base(message, innerException)
		{ }

        protected EntityCompilationException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {}

		public EntityCompilationException(string message, EntityElement element)
			: base(message)
		{
			_element = element;
		}

		public EntityCompilationException(string message, EntityElement element, Exception innerException)
			: base(message, innerException)
		{
			_element = element;
		}

        [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            if (info == null)
                throw new ArgumentNullException("info", Resources.ArgumentNullExceptionMessage);

            info.AddValue("_element", _element);
            base.GetObjectData(info, context);
        }
    }
}
